<html>
<head><meta charset="utf-8"><title>TAIT expected `[type error]` · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html">TAIT expected `[type error]`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244362389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/TAIT%20expected%20%60%5Btype%20error%5D%60/near/244362389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dominik Stolz <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html#244362389">(Jun 29 2021 at 23:38)</a>:</h4>
<p>Hi everyone! I was wondering what the expected behavior is for the following <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=86a2e58c143a916822a50ef052e142a5">example</a>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(min_type_alias_impl_trait)]</span><span class="w"></span>
<span class="k">type</span> <span class="nc">Foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="nb">Sized</span><span class="p">;</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nb">None</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">baz</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nb">Some</span><span class="p">(())</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>The compiler currently rejects this, saying <code>type annotations needed</code> for <code>bar</code> and <code>concrete type differs from previous defining opaque type use</code> for <code>bar</code>. If this is intended, it would be nice if the second error would not say <code>expected [type error], got Option&lt;()&gt;</code>. However, I think it would also make sense to accept the code since it also compiles if we replace <code>Foo</code> with <code>Option&lt;Foo&gt;</code> in the return types.</p>



<a name="244362780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/TAIT%20expected%20%60%5Btype%20error%5D%60/near/244362780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html#244362780">(Jun 29 2021 at 23:45)</a>:</h4>
<p>i guess it's seeing the <code>None</code> in <code>bar()</code> and treating it as <code>Option&lt;T&gt;::None where T: Sized</code> or something? but it hasn't solved for a concrete type for <code>T</code> yet…</p>



<a name="244362991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/TAIT%20expected%20%60%5Btype%20error%5D%60/near/244362991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html#244362991">(Jun 29 2021 at 23:48)</a>:</h4>
<p>interestingly, if i swap the two function definitions, i get a somewhat related error</p>
<div class="codehilite"><pre><span></span><code>error: concrete type differs from previous defining opaque type use
 --&gt; src/lib.rs:4:1
  |
4 | fn bar() -&gt; Foo { None }
  | ^^^^^^^^^^^^^^^ expected `Option&lt;()&gt;`, got `[type error]`
</code></pre></div>
<p>i would expect the "defining use" to feed into the type inference for the <code>None</code></p>



<a name="244383594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/TAIT%20expected%20%60%5Btype%20error%5D%60/near/244383594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html#244383594">(Jun 30 2021 at 06:52)</a>:</h4>
<p>Both bar and baz are defining uses.</p>



<a name="244383621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/TAIT%20expected%20%60%5Btype%20error%5D%60/near/244383621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html#244383621">(Jun 30 2021 at 06:52)</a>:</h4>
<p>Making type inference dependent on the order of evaluation would be problematic. Especially for incr comp.</p>



<a name="244383679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/TAIT%20expected%20%60%5Btype%20error%5D%60/near/244383679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html#244383679">(Jun 30 2021 at 06:53)</a>:</h4>
<blockquote>
<p>i would expect the "defining use" to feed into the type inference for the <code>None</code></p>
</blockquote>
<p>That would require type inference on bar and baz to be done at the same type if you don't want to make it order dependent.</p>



<a name="245096499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/TAIT%20expected%20%60%5Btype%20error%5D%60/near/245096499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html#245096499">(Jul 06 2021 at 20:46)</a>:</h4>
<p><span class="user-mention" data-user-id="302700">@Dominik Stolz</span> this is expected to be an error</p>



<a name="245096523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/TAIT%20expected%20%60%5Btype%20error%5D%60/near/245096523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html#245096523">(Jul 06 2021 at 20:47)</a>:</h4>
<p>we currently require that <em>each defining use completely defines the type</em></p>



<a name="245096548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/TAIT%20expected%20%60%5Btype%20error%5D%60/near/245096548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/TAIT.20expected.20.60.5Btype.20error.5D.60.html#245096548">(Jul 06 2021 at 20:47)</a>:</h4>
<p>so <code>bar</code> would hve to be <code>None::&lt;()&gt;</code> or something like that</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>